import time


def mylog(fun):
    print(f'mylog decorated for {fun.__name__} started...')

    def log_func():
        print(f'{fun.__name__} execute')
        fun()
        print(f'{fun.__name__} end')

    print(f'mylog decorated for {fun.__name__} end...')
    return log_func


def cost_time(fun):
    print(f'cost_time decorated for {fun.__name__} started...')

    def time_func():
        start_time = time.time()
        fun()
        end_time = time.time()
        print(f'{fun.__name__}--time cost:{end_time - start_time}')

    print(f'cost_time decorated for {fun.__name__} end...')
    return time_func



@mylog
@cost_time
def fun2():
    print('fun2() self executed')


fun2()
# 函数定义阶段：
# 相当于：
# fun2 = cost_time(fun2)
# fun2 = mylog(fun2)
# 也相当于：
# fun2 = mylog(cost_time(fun2))
# 定义阶段：先执行cost_time函数，再执行mylog函数
